#ifndef __REAL_VECTOR_H
#define __REAL_VECTOR_H

#include <stddef.h>

typedef struct vector {
	unsigned char *data;
	size_t size;
	size_t capacity;
} vector_t;


#define vector_data(v) ((v)->data)
#define vector_size(v) ((v)->size)
#define vector_capacity(v) ((v)->capacity)

#define vector_init(v) ( \
	(v)->data = 0, (v)->size = 0, (v)->capacity = 0)

#define vector_destory(v) do { \
	if ((v)->data != 0) \
		free ((v)->data); \
	(v)->data = 0, (v)->size = 0, (v)->capacity = 0; \
} while (0)

int vector_push(vector_t *v, const void *data, size_t size);
size_t vector_pop(vector_t *v, void *data, size_t size);
int vector_resize(vector_t *v, size_t newsize);
int vector_reserve(vector_t *v, size_t newcap);

#define vec_obj_data(v, type) ((type*) (v)->data)
#define vec_obj_size(v, type) ((v)->size / sizeof(type))
#define vec_obj_capacity(v, type) ((v)->capacity / sizeof(type))

#define vec_obj_push(v, type, objptr) vector_push(v, objptr, sizeof(type))
#define vec_obj_pop(v, type, objptr) vector_pop(v, objptr, sizeof(type))
#define vec_obj_resize(v, type, newsize) vector_resize(v, sizeof(type) * newsize)
#define vec_obj_reserve(v, type, newcap) vector_reserve(v, sizeof(type) * newcap)


#endif
